const app = getApp();
const req = require("../../utils/http.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    height:'',
    type:'',
    userInfo:'',
    list:[],
    newList:[],
    total:'',
    page:0,
    size:10,
    contNull:false
  },

  balanceClik(page,size){
    let t = this
    let type = t.data.type
    let mobile = t.data.userInfo.mobile
    let params = { type, mobile}
    let url=''
    if(type==2){ //消费记录
      url = `/mini/selectConsumeList/${page}/${size}`
    }else{
      url = `/mini/selectPointOrFeeList/${page}/${size}`
    }
    req.wxReq(url, "POST", params).then(res=>{
      if(res.data.code==200){
        console.log(res.data.result.records)
        if (res.data.result.records.length<=0){
          t.setData({
            contNull:true
          })
          return
        }
        let list = res.data.result.records
       
        let newList = t.data.newList.concat(list)
        t.setData({
          newList,
          total: res.data.result.total
        })
      } else {
        wx.showToast({
          title: res.data.message,
          icon: 'none',
          duration: 1500
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let t = this
    let page = t.data.page;
    let size = t.data.size;
    this.setData({
      userInfo: wx.getStorageSync('isUserinfo'),
      type: options.type
    })
    setTimeout(()=>{
      this.balanceClik(page,size)
    },500)

    wx.getSystemInfo({
      success: (res) => {
        this.setData({
          height: res.windowHeight
        })

      }
    })
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    let t = this
    wx.showLoading({
      title: '玩命加载中....',
    })
    let page = t.data.page+1
    t.setData({
      page,
    })
    if(page>Math.ceil(t.data.total/t.data.size)){
      wx.showToast({
        title: '到底了！！！',
        icon: 'none'
      })
      return;
    }
    t.balanceClik(page,t.data.size)
    wx.hideLoading()
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})